package com.hlxl.viewpointrest.service;

import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * Created by wyy on 18-5-7
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {

        try {
            User user = UserLocalServiceUtil.getUserByScreenName(PortalUtil.getDefaultCompanyId(), s);
            return new org.springframework.security.core.userdetails.User(s, user.getPassword(), Collections.emptyList());
        } catch (Exception e) {
            e.printStackTrace();
            throw new UsernameNotFoundException(s);
        }
    }
}
